Page({
  data: {
    userPoints: 1280,
    showRulesPopup: false,
    dailyTasks: [
      {
        id: 1,
        name: '每日签到',
        description: '连续签到额外奖励',
        points: 10,
        icon: 'images/sign.jpg',
        completed: false
      },
      {
        id: 2,
        name: '分享小程序',
        description: '分享给好友即可得积分',
        points: 20,
        icon: 'images/share.jpg',
        completed: false
      },
      {
        id: 3,
        name: '完善资料',
        description: '补充个人信息',
        points: 50,
        icon: 'images/profile.png',
        completed: true
      }
    ],
    pointsRecords: [
      {
        id: 1,
        type: '签到奖励',
        points: 10,
        time: '2024-03-10 10:30'
      },
      {
        id: 2,
        type: '积分兑换',
        points: -100,
        time: '2024-03-09 15:20'
      },
      {
        id: 3,
        type: '消费奖励',
        points: 200,
        time: '2024-03-08 14:30'
      }
    ],
    pointsRules: [
      {
        id: 1,
        title: '签到规则',
        description: '每日签到可获得10积分，连续签到7天额外奖励30积分'
      },
      {
        id: 2,
        title: '消费规则',
        description: '每消费1元可获得1积分'
      },
      {
        id: 3,
        title: '积分有效期',
        description: '积分有效期为一年，请及时使用'
      }
    ]
  },

  showRules() {
    this.setData({
      showRulesPopup: true
    });
  },

  hideRules() {
    this.setData({
      showRulesPopup: false
    });
  },

  completeTask(e) {
    const taskId = e.currentTarget.dataset.id;
    const tasks = this.data.dailyTasks.map(task => {
      if (task.id === taskId && !task.completed) {
        // 完成任务逻辑
        wx.showToast({
          title: '获得' + task.points + '积分',
          icon: 'success'
        });
        return { ...task, completed: true };
      }
      return task;
    });
    this.setData({
      dailyTasks: tasks
    });
  },

  navigateToExchange() {
    wx.navigateTo({
      url: '/pages/points-exchange/index'
    });
  },

  navigateToTask() {
    wx.navigateTo({
      url: '/pages/points-task/index'
    });
  }
}); 